<template>
  <a-drawer width="50%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
    <a-descriptions title="详细信息" bordered>
      <a-descriptions-item label="姓名">
        {{ form.memberName }}
      </a-descriptions-item>
      <a-descriptions-item label="性别">
        {{ form.memberSex === 1? '男':'女' }}
      </a-descriptions-item>
      <a-descriptions-item label="头像">
        <a-avatar shape="square" size="large" :src="form.memberAvatarUrl" icon="user" />
      </a-descriptions-item>

      <a-descriptions-item label="专业">
        {{ form.subjectName }}
      </a-descriptions-item>

      <a-descriptions-item label="班级">
        {{ form.memberClass }}
      </a-descriptions-item>

      <a-descriptions-item label="身份">
        <a-tag v-if="form.memberType === 0" color="blue">
          普通会员
        </a-tag>
        <a-tag v-if="form.memberType === 1" color="blue">
          志愿者(待审核)
        </a-tag>
        <a-tag v-if="form.memberType === 2" color="blue">
          志愿者
        </a-tag>
        <a-tag v-if="form.memberType === 3" color="blue">
          审核未通过
        </a-tag>
        <a-tag v-if="form.memberType === 4" color="blue">
          管理员
        </a-tag>

      </a-descriptions-item>

      <a-descriptions-item label="open_id" :span="3">
        {{ form.memberAppId }}

      </a-descriptions-item>

      <a-descriptions-item label="学号" :span="2">
        {{ form.numberNum }}

      </a-descriptions-item>

      <a-descriptions-item label="服务时长">
        {{ form.memberDuration }} 小时

      </a-descriptions-item>

      <a-descriptions-item label="爱好" >
        {{ form.memberHobby }}
      </a-descriptions-item>
    </a-descriptions>
  </a-drawer>
</template>

<script>
import { getMember, addMember, updateMember } from '@/api/angel/member'

export default {
  name: 'CreateForm',
  props: {
    memberSexOptions: {
      type: Array,
      required: true
    },
    memberTypeOptions: {
      type: Array,
      required: true
    }
  },
  components: {
  },
  data () {
    return {
      loading: false,
      formTitle: '',
      // 表单参数
      form: {
        memberId: null,
        memberAppId: null,
        memberName: null,
        memberSex: null,
        memberSubject: null,
        memberClass: null,
        memberHobby: null,
        memberType: null,
        memberDuration: null,
        numberNum: null,
        memberAvatarUrl: null,
        memberNickname: null
      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    onClose () {
      this.open = false
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        memberId: null,
        memberAppId: null,
        memberName: null,
        memberSex: null,
        memberSubject: null,
        memberClass: null,
        memberHobby: null,
        memberType: null,
        memberDuration: null,
        numberNum: null,
        memberAvatarUrl: null,
        memberNickname: null,
        subjectName: null
      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (row, ids) {
      this.reset()
      this.formType = 2
      const memberId = row ? row.memberId : ids
      getMember(memberId).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.form.memberId !== undefined && this.form.memberId !== null) {
            updateMember(this.form).then(response => {
              this.$message.success(
                '修改成功',
                3
              )
              this.open = false
              this.$emit('ok')
            })
          } else {
            addMember(this.form).then(response => {
              this.$message.success(
                '新增成功',
                3
              )
              this.open = false
              this.$emit('ok')
            })
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>
